package gui;

import gui.activity.ActivityStackSupervisor;
import gui.framework.Loader;
import gui.framework.file.PathUtils;
import gui.framework.intent.Intent;
import gui.resource.GUIResource;
import gui.resource.Resource;

/**
 * 当前应用上下文对象
 * 
 * @author chenj_000
 *
 */
public class Context {
	private static String APPLICATION_PATH;
	private static Resource RESOURCE;
	private static Loader LOADER;

	/**
	 * 以下定义一些常量
	 */
	public static final String MATCH_PARENT = "match_parent";
	public static final String CENTER = "center";

	/**
	 * 获得应用路径
	 * 
	 * @return
	 */
	public static String getContextPath() {
		return APPLICATION_PATH;
	}

	public void startLuncher() {
		APPLICATION_PATH = PathUtils.getApplicationPath(Context.class);
		RESOURCE = GUIResource.getResource();
		LOADER = new GUILoader();
		LOADER.loadManifest();

		Intent intent = new Intent();
		intent.setAction(Intent.action.MAIN);
		intent.addCategory(Intent.category.LAUNCHER);
		startActivity(intent);
	}

	/**
	 * 获得资源控制对象
	 * 
	 * @return
	 */
	public static Resource getResource() {
		return RESOURCE;
	}

	public void startActivity(Intent intent) {
		Activity activity = LOADER.getActivity(intent);
		ActivityStackSupervisor.startActivity(activity, intent);
	}

	public void startActivity(Class<? extends Activity> activity) {
		Activity a = LOADER.getActivity(activity);
		ActivityStackSupervisor.startActivity(a, null);
	}
}
